package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Depot;
import cn.wolfcode.crm.service.IDepotService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("depot")
public class DepotController {
    @Autowired
    private IDepotService depotService;

    //查询所有仓库
    @RequestMapping("selectAll")
    @ResponseBody
    public List<Depot> selectAll(){
        return depotService.selectAll();
    }

    //只负责转发到仓库页面
    @RequestMapping("view")
    public String view() {
        return "depot/depot";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Depot depot){
        try {
            depotService.saveOrUpdate(depot);
            return JSONResult.success("保存成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("保存失败");
        }
    }


    @RequestMapping("delete")
    @ResponseBody
    public Object delete( Long id) {
        depotService.deleteByPrimaryKey(id);
        return new JSONResult();
    }

    //根据员工id修改员工的状态
    @RequestMapping("changeState")
    @ResponseBody
    public JSONResult changeState(Long depotID){
        try {
            depotService.changeState(depotID);
            return JSONResult.success("保存成功!");
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.mark("操作失败");
        }
    }
}
